package com.itboye.ihomebank.me;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.MyGuanJiaAdapter01;
import com.itboye.ihomebank.base.BaseFragment;
import com.itboye.ihomebank.bean.ChanKanWeiXiuBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.XListView;
import com.itboye.ihomebank.presenter.RepairPersenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

/**
 * 我的生活管家（派单中）
 * 
 */
public class ActivityMyGuanJia01 extends BaseFragment implements Observer {
	XListView guanli_xlistView;

	MyGuanJiaAdapter01 adapter;

	List<ChanKanWeiXiuBean> listBean;

	RepairPersenter repairPersenter;
	TextView imgEmpty;

	@Override
	public int initView() {
		return R.layout.activity_my_guanjia;
	}

	@Override
	public void onMyActivityCreated() {
		showProgressDialog("数据加载中,请稍后", true);
		guanli_xlistView.setPullRefreshEnable(false);

		String uid = (String) SPUtils.get(getActivity(), null,
				SPContants.USER_ID, "");

		repairPersenter = new RepairPersenter(this);
		repairPersenter.chanKanWeiXiu(uid, "0");

	}

	@SuppressWarnings("unchecked")
	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = handlerError(data);
		// ByAlert.alert(entity.getData());
		if (entity != null) {
			if (!entity.getCode().equals(0)) {
				if (entity.getEventType() == RepairPersenter.weixiuZhuangTai_success) {
					List<ChanKanWeiXiuBean> bean = (List<ChanKanWeiXiuBean>) entity
							.getData();
					if (bean != null) {
						if (bean.size() <= 0) {
							imgEmpty.setVisibility(View.VISIBLE);
						} else {
							imgEmpty.setVisibility(View.GONE);
						}
					}
					if (bean.size() <= 0) {
						imgEmpty.setVisibility(View.VISIBLE);
					}
					adapter = new MyGuanJiaAdapter01(getActivity(), bean,
							R.layout.item_my_guanjia);
					guanli_xlistView.setAdapter(adapter);

				} else if (entity.getEventType() == RepairPersenter.weixiuZhuangTai_fail) {
					ByAlert.alert(entity.getData());

				}
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
